//vip等级管理初始化
var VipLevel = {
    id: "VipLevelTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

//初始化表格的列
VipLevel.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: false, align: 'center', valign: 'middle', width: '50px'},
        {title: 'vip等级', field: 'vipLevelName', align: 'center', valign: 'middle', sortable: true},
        {title: '积分兑换系数', field: 'integralFactor', align: 'center', valign: 'middle', sortable: true},
        {title: '排序', field: 'num', align: 'center', valign: 'middle', sortable: true},
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle', sortable: true}];
};

VipLevel.check = function () { // 检查是否选中
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        VipLevel.seItem = selected[0];
        return true;
    }
};

//点击添加
VipLevel.openAddVipLevel = function () {
    var index = layer.open({
        type: 2,
        title: '添加vip等级',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/vipLevel/vipLevel_add'
    });
    this.layerIndex = index;
};

//积分规则
VipLevel.openIntegralRule = function () {
    var index = layer.open({
        type: 2,
        title: '积分规则',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/vipLevel/to_integralRule'
    });
    this.layerIndex = index;
};

//打开查看vip等级详情
VipLevel.openVipLevelDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: 'vip等级详情',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/vipLevel/vipLevel_update/' + VipLevel.seItem.id
        });
        this.layerIndex = index;
    }
};

//删除部门
VipLevel.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/vipLevel/delete/" + this.seItem.id, function (data) {
            Feng.success("删除成功!");
            VipLevel.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
    }
};

//查询表单提交参数对象 @returns {{}}
VipLevel.formParams = function () {
    var queryData = {};
    queryData['vipLevelName'] = $("#vipLevelName").val();
    return queryData;
};

VipLevel.resetSearch = function () {
    $("#vipLevelName").val("");
    VipLevel.search();
};

//查询列表
VipLevel.search = function () {
    VipLevel.table.refresh({query: VipLevel.formParams()});
};

$(function () {
    var defaultColunms = VipLevel.initColumn();
    var table = new BSTable(VipLevel.id, "/vipLevel/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(VipLevel.formParams());
    VipLevel.table = table.init();
    VipLevel.table = table;
});
